<?php
/**
 * Created by PhpStorm.
 * UsersF: Mloong
 * Date: 2018/11/29
 * Time: 10:28
 */

namespace app\admin\controller;


use app\admin\model\Log;
use think\auth\Auth;
use think\Controller;
use think\facade\Session;

class BaseController extends Controller
{
    protected $admin_user;
    function initialize()
    {
        if(!Session::get('user','user_session')){
            $this->success('请登陆','/admin');
            exit();
        }
        $str = $this->actionFun();
        $this->writeLog($str);
    }
    protected function writeLog($str)
    {
        $data = array();
        $data['username'] = Session::get('user','user_session');
        $data['action'] = $str;
        $data['add_time'] = now_time();
        $data['ip'] = ip();
        Log::writeLog($data);
    }
    protected function actionFun()
    {
        //把模块、控制器和方法转换成一个字符串
        $method = $this->request->method();
        $module = $this->request->module();
        $controller = $this->request->controller();
        $action = $this->request->action();
        $str="[ $method : $module || $controller || $action ]";
        return $str;
    }
}